package com.creditharmony.car.loan.dao.impl;

import org.springframework.stereotype.Repository;
import com.creditharmony.car.common.base.dao.impl.BaseDaoImpl;
import com.creditharmony.car.common.exception.UserException;
import com.creditharmony.car.common.utils.ErrorType;
import com.creditharmony.car.loan.dao.CarLoanCustomerDao;
import com.creditharmony.car.loan.entity.CarLoanCustomerEntity;
/**
 * 借款客户
 * @Class Name CarCustomerDaoImpl
 * @author zqa
 * @Create In 2018年1月26日
 */
@Repository
public class CarCustomerDaoImpl extends BaseDaoImpl<CarLoanCustomerEntity> implements CarLoanCustomerDao{
    /**
     * 插入客户个人信息
     * @param record 客户个人信息数据
     */
    public void insertCarCustomer(CarLoanCustomerEntity record) {
        try {
            openSession().insert(getNamespace() + ".insertCarCustomer", record);
        } catch (Exception e) {
            throw new UserException(ErrorType.ERROR_SYS_DB, "客户信息录入 出现数据库异常.", e);
        }
    }

    /**
     * 获取单条数据
     * @param loanCode 借款编号
     * @return 客户个人信息查询结果
     */
    public CarLoanCustomerEntity selectByLoanCode(String loanCode) {
        CarLoanCustomerEntity outEntity = null;
        try {
            outEntity = openSession().selectOne(getNamespace() + ".selectByLoanCode", loanCode);
        } catch (Exception e) {
            throw new UserException(ErrorType.ERROR_SYS_DB, "客户个人信息查询数据执行出现异常.", e);
        }
        return outEntity;
    }

    /**
     * 更新客户个人信息
     * @param record 客户个人信息数据
     */
    public void updateCarLoanCustomer(CarLoanCustomerEntity record) {
        try {
            openSession().update(getNamespace() + ".updateCarLoanCustomer", record);
        } catch (Exception e) {
            throw new UserException(ErrorType.ERROR_SYS_DB, "客户信息修改 出现数据库异常.", e);
        }
    }
}
